%% This code reproduces Table 1.
%% By adjusting the data path in line 18 and the output file name in line 42, 
%% this same script can be used to generate all CSV files like '15min_B005.csv',
%% which serve as inputs for Robust_Table.m.

final = cell(19,10);

FF = [1 3 4 5 6];
arr = cell(5,1);
arr{1,1} = [1 2 3];
arr{2,1} = [1 4 5 2 6 7 3 8 9];
arr{3,1} = [1 5 6 2 7 8 3 9 10 4 11 12];
arr{4,1} = [1 6 7 2 8 9 3 10 11 4 12 13 5 14 15];
arr{5,1} = [1 7 8 2 9 10 3 11 12 4 13 14 5 15 16 6 17 18];

 for i = 1:5

    load(['B005/Result_K_',num2str(FF(i)) '.mat'])

    if FF(i)~=4
        final(1:3+3*(FF(i)-1),2*i-1) = num2cell(Lambda_hat_AJX(:,arr{i,1})'*100);
        temp = sqrt(diag(Vn_AJX));
        final(1:3+3*(FF(i)-1),2*i)   = num2cell(Lambda_hat_AJX(:,arr{i,1})'./temp(arr{i,1},:));
    else
        final(1:3+3*(FF(i)-2),2*i-1) = num2cell(Lambda_hat_AJX(:,[1 5 6 2 7 8 3 9 10])'*100);
        temp = sqrt(diag(Vn_AJX));
        final(1:3+3*(FF(i)-2),2*i) = num2cell(Lambda_hat_AJX(:,[1 5 6 2 7 8 3 9 10])'./temp([1 5 6 2 7 8 3 9 10],:));
        final(16:18,2*i-1) = num2cell(Lambda_hat_AJX(:,[4 11 12])'*100);
        final(16:18,2*i) = num2cell(Lambda_hat_AJX(:,[4 11 12])'./temp([4 11 12], :));
    end
    final(19,2*i-1) = num2cell(mean(R2_t)*100);
 end
 
 final = cellfun(@(x) round(x,2),final,'UniformOutput',false);
 final(:,[2 4 6 8 10]) = cellfun(@num2str, final(:,[2 4 6 8 10]),'UniformOutput',false);
 final(1:3,2) = cellfun(@(x) ['$(',x,')$'], final(1:3,2),'UniformOutput',false);
 final(1:9,4) = cellfun(@(x) ['$(',x,')$'], final(1:9,4),'UniformOutput',false);
 final([1:9 16:18],6) = cellfun(@(x) ['$(',x,')$'], final([1:9 16:18],6),'UniformOutput',false);
 final(1:15,8) = cellfun(@(x) ['$(',x,')$'], final(1:15,8),'UniformOutput',false);
 final(1:18,10) = cellfun(@(x) ['$(',x,')$'], final(1:18,10),'UniformOutput',false);
 T = cell2table(final);
 writetable(T, '15min_B005.csv')
 
 
 